<template>
    <div class="system-mechanism-container">
        <el-form :inline="true" ref="form" class="system-search-form" :model="searchForm">
            <el-form-item>
                <el-select v-model="searchForm.category" class="type-select" size="small">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="正式" :value="1"></el-option>
                    <el-option label="试用" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-select v-model="searchForm.province" filterable clearable placeholder="请选择省" @change="getCity" size="small">
                    <el-option
                        v-for="item in provinceList"
                        :key="item.i"
                        :label="item.n"
                        :value="item.i">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-select v-model="searchForm.city" filterable clearable placeholder="请选择市" @change="getArea" size="small">
                    <el-option
                        v-for="item in cityList"
                        :key="item.i"
                        :label="item.n"
                        :value="item.i">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-select v-model="searchForm.area" filterable clearable placeholder="请选择区" size="small">
                    <el-option
                        v-for="item in areaList"
                        :key="item.i"
                        :label="item.n"
                        :value="item.i">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-input type="text" maxlength="100" v-model="searchForm.name" @keyup.enter.native="toFirstPage()" placeholder="机构名称" size="small"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button class="sub-btn" type="primary" size="small" @click="toFirstPage()">查询</el-button>
            </el-form-item>
        </el-form>
        <div class="table-box">
            <el-button class="add-btn" type="primary" size="small" icon="el-icon-plus" v-auth="{code: 300001000001}" @click="showAddDialog">新增</el-button>
            <el-table
                ref="tableData"
                :data="tableData"
                tooltip-effect="light"
                border
                :max-height="tableHeight"
                @sort-change="sortChange"
                class="data-table">
                <el-table-column
                    label="序号"
                    align="center"
                    type="index"
                    width="50">
                </el-table-column>
                <el-table-column
                    label="机构类别"
                    align="center"
                    width="80">
                    <template slot-scope="scope">
                        {{scope.row.organClassification | getCategory}}
                    </template>
                </el-table-column>
                <el-table-column
                    label="所在地"
                    show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{getFullAddress(scope.row)}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="address"
                    label="详细地址"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="机构名称"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="supOrganIdName"
                    label="上级机构"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="organCode"
                    align="center"
                    label="机构代码"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="organTypeName"
                    align="center"
                    label="机构类型"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    align="center"
                    label="医院等级"
                    show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{scope.row | getOrgLevel}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="people"
                    align="center"
                    label="联系人"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="phone"
                    align="center"
                    label="联系电话"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="createdName"
                    align="center"
                    label="创建人"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                    prop="createdTime"
                    label="创建时间"
                    align="center"
                    width="160"
                    sortable="custom"
                    show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{parseTime(new Date(scope.row.createdTime).getTime())}}
                    </template>
                </el-table-column>
                <el-table-column
                    label="启/停"
                    align="center"
                    width="100"
                    show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.state" size="small" :disabled="!showBtnAuth(300001000002)" @change="toChangeState(scope.$index, scope.row)"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="center"
                    width="80"
                    show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button type="text" size="small" v-auth="{code: 300001000002}" @click="tableEdit(scope.$index, scope.row)">
                            编辑
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="tableData.length > 0" :total="total" :page.sync="currentPage" :limit.sync="pageSize"
                        @pagination="getData"/>
        </div>
        <el-dialog
            :title="isAdd ? '新增机构' : '编辑机构'"
            :visible.sync="dialogVisible"
            :close-on-click-modal="false"
            @close="closeDialog"
            center
            width="40%">
            <el-form :inline="true" ref="dialogForm" class="dialog-form" :rules="editFormRules" :model="editForm" label-width="80px">
                <el-form-item label="机构类别" class="category" prop="category">
                    <el-radio v-model="editForm.category" :label="1">正式</el-radio>
                    <el-radio v-model="editForm.category" :label="2">试用</el-radio>
                </el-form-item>
                <el-form-item label="截止日期" prop="endDate">
                    <el-date-picker
                        v-model="editForm.endDate"
                        size="small"
                        type="date"
                        value-format="yyyy-MM-dd"
                        :picker-options="pickerOptions"
                        placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="截止日期前" class="end-date-tip" prop="endDateTip">
                    <el-input type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="editForm.endDateTip" size="small"></el-input>天提醒
                </el-form-item>
                <el-form-item label="所属地区" class="form-address" prop="province">
                    <el-select v-model="editForm.province" filterable clearable placeholder="请选择省" @change="getDialogCity" class="province" size="small">
                        <el-option
                            v-for="item in provinceList"
                            :key="item.i"
                            :label="item.n"
                            :value="item.i">
                        </el-option>
                    </el-select>
                    <el-select v-model="editForm.city" filterable clearable placeholder="请选择市" @change="getDialogArea" class="city" size="small">
                        <el-option
                            v-for="item in dialogCityList"
                            :key="item.i"
                            :label="item.n"
                            :value="item.i">
                        </el-option>
                    </el-select>
                    <el-select v-model="editForm.area" filterable clearable placeholder="请选择区" class="area" size="small">
                        <el-option
                            v-for="item in dialogAreaList"
                            :key="item.i"
                            :label="item.n"
                            :value="item.i">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="详细地址" class="full-address-info" prop="address">
                    <el-input type="text" maxlength="100" v-model="editForm.address" placeholder="请输入详细地址" class="address" size="small"></el-input>
                </el-form-item>
                <el-form-item label="机构名称" prop="name">
                    <el-input type="text" maxlength="100" v-model="editForm.name" placeholder="请输入机构名称" size="small"></el-input>
                </el-form-item>
                <el-form-item label="机构代码" prop="code">
                    <el-input type="text" maxlength="100" v-model="editForm.code" placeholder="请输入机构代码" size="small"></el-input>
                </el-form-item>
                <el-form-item label="机构等级" prop="level">
                    <el-select v-model="editForm.level" filterable placeholder="请选择机构等级" size="small">
                        <el-option
                            v-for="item in levelList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="上级机构" prop="mechanism">
                    <el-cascader
                        class="go-out"
                        v-model="editForm.mechanism"
                        :show-all-levels="false"
                        :options="mechanismList"
                        :props="{ checkStrictly: true, emitPath: false }"
                        filterable
                        clearable
                        size="small">
                    </el-cascader>
                </el-form-item>
                <el-form-item label="机构类型" prop="type">
                    <el-select v-model="editForm.type" filterable placeholder="请选择机构类型" size="small">
                        <el-option
                            v-for="item in typeList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系人" prop="contactPerson">
                    <el-input type="text" maxlength="20" v-model="editForm.contactPerson" placeholder="请输入联系人" size="small"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input type="text" maxlength="15" v-model="editForm.phone" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入联系电话" size="small"></el-input>
                </el-form-item>
                <el-form-item label="启/停" class="switch-box" prop="status">
                    <el-switch v-model="editForm.status"></el-switch>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeDialog" size="small">取 消</el-button>
                <el-button type="primary" @click="submitEditForm('dialogForm')" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {getMechanismList, addMechanism, editMechanism, changeState} from '@/api/system/mechanism'
    import {getSortString, showBtnAuth} from '@/utils/filters'
    import orgLevel from '@/assets/json/orgLevel.json'
    import Pagination from '@/components/Pagination'
    import regions from '@/assets/json/regions.json'
    import orgType from '@/assets/json/orgType.json'

    export default {
        name: 'index',
        data () {
            // 弹框地址选择验证规则
            const checkAddress = (rule, value, callback) => {
                if (this.provinceList.length && this.editForm.province === '') {
                    return callback(new Error('请选择省'))
                } else if (this.dialogCityList.length && this.editForm.city === '') {
                    return callback(new Error('请选择市'))
                } else if (this.dialogAreaList.length && this.editForm.area === '') {
                    return callback(new Error('请选择区'))
                } else {
                    return callback()
                }
            }
            return {
                // 搜索表单
                searchForm: {
                    category: 0,
                    province: '',
                    city: '',
                    area: '',
                    name: ''
                },
                // 机构列表
                mechanismList: [],
                // 表格数据
                tableData: [],
                // 数据总数
                total: 1,
                // 当前页
                currentPage: 1,
                // 每页数量
                pageSize: 10,
                // 表格高度
                tableHeight: 100,
                // 显示弹框
                dialogVisible: false,
                // 弹框表单
                editForm: {
                    // 机构类别
                    category: 1,
                    // 截止日期
                    endDate: '',
                    // 截止日期前提醒
                    endDateTip: '30',
                    // 省
                    province: '',
                    // 市
                    city: '',
                    // 区
                    area: '',
                    // 详细地址
                    address: '',
                    // 机构名称
                    name: '',
                    // 机构代码
                    code: '',
                    // 机构等级
                    level: '',
                    // 上级机构
                    mechanism: '',
                    // 机构类型
                    type: '',
                    // 联系人姓名
                    contactPerson: '',
                    // 联系电话
                    phone: '',
                    // 状态
                    status: true
                },
                // 省列表
                provinceList: [],
                // 市列表
                cityList: [],
                // 区列表
                areaList: [],
                // 弹框市列表
                dialogCityList: [],
                // 弹框区列表
                dialogAreaList: [],
                // 等级列表
                levelList: [],
                // 类型列表
                typeList: [],
                // 是否是新增
                isAdd: true,
                // 排序方式
                orderBy: null,
                // 排序字段
                sortMap: {},
                editFormRules: {
                    category: [
                        {required: true, message: '请选择机构类别', trigger: 'change'}
                    ],
                    endDate: [
                        {required: true, message: '请选择截止日期', trigger: 'change'}
                    ],
                    endDateTip: [
                        {required: true, message: '请输入提醒时间', trigger: ['blur', 'change']}
                    ],
                    province: [
                        {required: true, validator: checkAddress, trigger: 'change'}
                    ],
                    address: [
                        {required: true, message: '请填写详细地址', trigger: ['blur', 'change']}
                    ],
                    name: [
                        {required: true, message: '请填写机构名称', trigger: ['blur', 'change']}
                    ],
                    code: [
                        {required: true, message: '请填写机构代码', trigger: ['blur', 'change']}
                    ],
                    level: [
                        {required: true, message: '请选择机构等级', trigger: 'change'}
                    ],
                    type: [
                        {required: true, message: '请选择机构类型', trigger: 'change'}
                    ],
                    contactPerson: [
                        {required: true, message: '请填写联系人', trigger: ['blur', 'change']}
                    ],
                    phone: [
                        {required: true, message: '请填写联系人电话', trigger: ['blur', 'change']}
                    ]
                },
                pickerOptions: {
                    disabledDate (time) {
                        return time.getTime() < Date.now()
                    }
                },
                // 使用储存的数据，不去请求
                useStore: false
            }
        },
        created () {
            // tags判断入口是否从选项卡进入
            this.useStore = this.$route.query.tags === 'tags'
            let height = document.documentElement.clientHeight - 213 - 10 - 78 - 5
            this.tableHeight = height > 107 ? height : 107
            this.getMechanismList()
            this.getAddressList()
            this.initData()
            this.getData()
            this.levelList = orgLevel.level
            this.typeList = orgType.type
        },
        mounted () {
            window.onresize = () => {
                // 213=其他元素高度60+50+48+55 10=距离底部边距 78=分页组件高度 5=适应性调整
                let height = document.documentElement.clientHeight - 213 - 10 - 78 - 5
                this.tableHeight = height > 107 ? height : 107
            }
        },
        methods: {
            showBtnAuth,
            /**
             * 初始化页面参数
             */
            initData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                if (JSON.stringify(query) !== '{}') {
                    this.searchForm.category = query.organClassification || 0
                    this.searchForm.province = query.province || ''
                    if (query.province) this.getCity(query.province)
                    this.searchForm.city = query.city || ''
                    if (query.city) this.getArea(query.city)
                    this.searchForm.area = query.regionID || ''
                    this.searchForm.name = query.keyword || ''
                    this.currentPage = query.index || 1
                    this.pageSize = query.pageSize || 10
                    this.orderBy = query.orderBy || null
                }
            },
            /**
             * 获取机构列表
             */
            getMechanismList () {
                let mechanismList = this.getLocalStorage('userInfo', 'mechanism')
                let parentList = []
                mechanismList.forEach(item => {
                    // 一级机构
                    if (!item.pid) {
                        parentList.push({
                            value: item.id,
                            label: item.name,
                            children: []
                        })
                        // 有一级机构的二级机构
                        mechanismList.forEach(it => {
                            if (it.pid === item.id) {
                                parentList[parentList.length - 1].children.push({
                                    value: it.id,
                                    label: it.name,
                                    children: null
                                })
                            }
                        })
                        if (!parentList[parentList.length - 1].children.length) {
                            parentList[parentList.length - 1].children = null
                        }
                    } else {
                        // 二级机构
                        let parent = mechanismList.filter(i => item.pid === i.id)
                        if (!parent.length) {
                            parentList.push({
                                value: item.id,
                                label: item.name,
                                children: null
                            })
                        }
                    }
                })
                this.mechanismList = parentList
            },
            /**
             * 获取省列表
             */
            getAddressList () {
                this.provinceList = regions.a
            },
            /**
             * 获取市列表
             * @param val 选中的id
             */
            getCity (val) {
                this.searchForm.city = ''
                this.searchForm.area = ''
                this.cityList = this.getChildren(this.provinceList, val)
            },
            /**
             * 获取区列表
             * @param val 选中的id
             */
            getArea (val) {
                this.searchForm.area = ''
                this.areaList = this.getChildren(this.cityList, val)
            },
            /**
             * 获取弹框市列表
             * @param val 选中的id
             * @param way 触发方式
             */
            getDialogCity (val, way) {
                if (way !== 'edit') this.editForm.city = ''
                this.dialogCityList = this.getChildren(this.provinceList, val)
            },
            /**
             * 获取弹框区列表
             * @param val 选中的id
             * @param way 触发方式
             */
            getDialogArea (val, way) {
                if (way !== 'edit') this.editForm.area = ''
                this.dialogAreaList = this.getChildren(this.dialogCityList, val)
            },
            /**
             * 遍历获取地区子级
             * @param arr 当前地区列表
             * @param id 指定id
             */
            getChildren (arr, id) {
                let length = arr.length
                let list = []
                for (let i = 0; i < length; i++) {
                    if (arr[i].i === id) {
                        list = arr[i].c
                        break
                    }
                }
                return list
            },
            /**
             * 获取表格数据
             * @param type 是否重置页码
             */
            getData (type) {
                let params = {
                    organClassification: this.searchForm.category,
                    province: this.searchForm.province,
                    city: this.searchForm.city,
                    regionID: this.searchForm.area,
                    keyword: this.searchForm.name,
                    index: this.currentPage,
                    pageSize: this.pageSize,
                    orderBy: this.orderBy
                }
                this.setGetStore(this.$route.name, params)
                if (this.getSession(this.$route.name, 'getMechanismList') && this.useStore) {
                    this.useStore = false
                    let res = this.getSession(this.$route.name, 'getMechanismList')
                    if (res.code.toString() === '200') {
                        this.tableData = res.data.rows
                        this.sortMap = res.data.maps
                        this.total = res.data.total
                    }
                } else {
                    getMechanismList(params).then(res => {
                        this.useStore = false
                        this.setSession(this.$route.name, {getMechanismList: res})
                        if (res.code.toString() === '200') {
                            this.tableData = res.data.rows
                            this.sortMap = res.data.maps
                            this.total = res.data.total
                        } else {
                            this.$message.error(res.message)
                        }
                    })
                }
            },
            /**
             * 修改条件后从第一页开始
             */
            toFirstPage () {
                this.currentPage = 1
                this.getData()
            },
            /**
             * 排序修改
             * @param colData.prop 排序参数
             * @param colData.order 正序倒序 ascending 升序 descending 降序 null 不排序默认
             */
            sortChange (colData) {
                this.orderBy = getSortString(colData, this.sortMap)
                this.tableData = []
                this.currentPage = 1
                this.getData()
            },
            /**
             * 获取完整地址
             * @param row 行数据
             */
            getFullAddress (row) {
                let length = this.provinceList.length
                let province = ''
                let city = ''
                let region = ''
                for (let i = 0; i < length; i++) {
                    if (this.provinceList[i].i === row.province) {
                        province = this.provinceList[i].n
                        if (row.city) {
                            let cityLength = this.provinceList[i].c.length
                            for (let j = 0; j < cityLength; j++) {
                                if (this.provinceList[i].c[j].i === row.city) {
                                    city = this.provinceList[i].c[j].n
                                    if (row.regionID) {
                                        let regionLength = this.provinceList[i].c[j].c.length
                                        for (let q = 0; q < regionLength; q++) {
                                            if (this.provinceList[i].c[j].c[q].i === row.regionID) {
                                                region = this.provinceList[i].c[j].c[q].n
                                                break
                                            }
                                        }
                                    }
                                    break
                                }
                            }
                        }
                        break
                    }
                }
                return province + city + region
            },
            /**
             * 获取上级机构
             * @param row 行数据
             */
            getParentMechanism (row) {
                let allMechanism = this.getLocalStorage('userInfo', 'mechanism')
                if (allMechanism.length) {
                    let res = allMechanism.filter(item => item.id === row.supOrganId)
                    return res[0] ? res[0].name : ''
                }
                return ''
            },
            /**
             * 启动停止
             * @param index 索引
             * @param row 行数据
             */
            toChangeState (index, row) {
                let text = ''
                let title = ''
                if (row.state) {
                    text = `您确定启用"${row.name}"机构吗?`
                    title = '启用机构'
                } else {
                    text = `您确定停用"${row.name}"机构吗?停用后将不能再被使用!`
                    title = '停用机构'
                }
                this.$confirm(text, title, {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    this.changeIdState(row.id, row.state)
                }).catch(() => {
                    row.state = !row.state
                })
            },
            /**
             * 改变指定状态
             * @param id 数据id
             * @param state 状态
             */
            changeIdState (id, state) {
                let params = {
                    id: id,
                    state: state
                }
                changeState(params).then(res => {
                    if (res.code.toString() === '200') {
                        this.$message.success(state ? '启用成功' : '停用成功')
                        this.$store.dispatch('user/getUserInfoAgain')
                    } else if (res.code.toString() === '404') {
                        this.$message.error('未找到该机构')
                    } else {
                        this.$message.error(res.message)
                    }
                    this.getData()
                })
            },
            /**
             * 打开编辑弹框
             * @param index 索引
             * @param row 行数据
             */
            tableEdit (index, row) {
                this.isAdd = false
                this.editForm = {
                    category: row.organClassification ? row.organClassification : 1,
                    endDate: row.endDate ? this.parseTime(new Date(row.endDate).getTime(), '{y}-{m}-{d}') : this.parseTime(new Date().getTime() + 90 * 24 * 60 * 60 * 1000, '{y}-{m}-{d}'),
                    endDateTip: row.advancedDays ? row.advancedDays : '30',
                    id: row.id,
                    province: row.province,
                    city: row.city,
                    area: row.regionID,
                    address: row.address,
                    name: row.name,
                    code: row.organCode,
                    level: row.hospitalGrade,
                    mechanism: row.supOrganId,
                    type: row.organType,
                    contactPerson: row.people,
                    phone: row.phone,
                    status: row.state
                }
                this.getDialogCity(row.province, 'edit')
                this.getDialogArea(row.city, 'edit')
                this.dialogVisible = true
            },
            /**
             * 弹框关闭
             */
            closeDialog () {
                this.editForm = {
                    category: 1,
                    endDate: '',
                    endDateTip: '30',
                    province: '',
                    city: '',
                    area: '',
                    address: '',
                    name: '',
                    code: '',
                    level: '',
                    mechanism: '',
                    type: '',
                    contactPerson: '',
                    phone: '',
                    status: true
                }
                this.$refs['dialogForm'].resetFields()
                this.dialogVisible = false
            },
            /**
             * 点击新增打开弹窗
             */
            showAddDialog () {
                this.editForm.endDate = this.parseTime(new Date().getTime() + 90 * 24 * 60 * 60 * 1000, '{y}-{m}-{d}')
                this.isAdd = true
                this.dialogVisible = true
            },
            /**
             * 提交编辑内容
             * @param formName 表单名
             */
            submitEditForm (formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let params = {
                            organClassification: this.editForm.category,
                            endDate: this.parseTime(new Date(this.editForm.endDate).getTime(), '{y}-{m}-{d}') + ' 23:59:59',
                            advancedDays: Number(this.editForm.endDateTip),
                            province: this.editForm.province,
                            city: this.editForm.city,
                            regionID: this.editForm.area,
                            address: this.editForm.address,
                            name: this.editForm.name,
                            organCode: this.editForm.code,
                            hospitalGrade: this.editForm.level,
                            supOrganId: this.editForm.mechanism || null,
                            organType: this.editForm.type,
                            people: this.editForm.contactPerson,
                            phone: this.editForm.phone,
                            state: this.editForm.status
                        }
                        if (this.isAdd) {
                            addMechanism(params).then(res => {
                                if (res.code.toString() === '200') {
                                    this.$message.success('新增成功')
                                    this.$store.dispatch('user/getUserInfoAgain')
                                    this.closeDialog()
                                    this.getData()
                                } else {
                                    this.$message.error(res.message)
                                }
                            })
                        } else if (this.editForm.id === this.editForm.mechanism) {
                            this.$message.warning('不能选择自己作为上级机构!')
                        } else {
                            params.id = this.editForm.id
                            editMechanism(params).then(res => {
                                if (res.code.toString() === '200') {
                                    this.$message.success('保存成功')
                                    this.$store.dispatch('user/getUserInfoAgain')
                                    this.closeDialog()
                                    this.getData()
                                } else {
                                    this.$message.error(res.message)
                                }
                            })
                        }
                    } else {
                        return false
                    }
                })
            }
        },
        components: {
            Pagination
        },
        filters: {
            /**
             * 获取机构类型
             * @param row 行数据
             */
            getOrgType (row) {
                let res = orgType.type.filter(item => item.id === row.organClassification)
                return res[0] ? res[0].name : ''
            },
            /**
             * 获取机构等级
             * @param row 行数据
             */
            getOrgLevel (row) {
                let res = orgLevel.level.filter(item => item.id === row.hospitalGrade)
                return res[0] ? res[0].name : ''
            },
            /**
             * 获取机构类别
             * @param val 行数据
             */
            getCategory (val) {
                switch (val) {
                case '':
                    return ''
                case 1:
                    return '正式'
                case 2:
                    return '试用'
                }
            }
        },
        beforeDestroy () {
            window.onresize = null
        }
    }
</script>

<style lang="scss" scoped>
    .system-mechanism-container {
        .system-search-form {
            .el-form-item {
                margin-bottom: 0;
            }
            .type-select {
                width: 100px;
            }
        }
        .table-box {
            background: #fff;
            padding: 10px;
            box-sizing: border-box;
            height: calc(100vh - 183px);
            .add-btn {
                margin-bottom: 10px;
            }
        }
        /deep/.el-dialog {
            width: 800px!important;
            .el-dialog__body {
                padding: 10px;
                .dialog-form {
                    width: 90%;
                    margin: 0 auto;
                    .el-form-item {
                        width: 44%;
                        .el-input {
                            width: 220px;
                        }
                    }
                    .category {
                        width: 100%;
                    }
                    .end-date-tip {
                        .el-form-item__label {
                            width: 100px!important;
                        }
                        .el-input {
                            width: 80px;
                            margin-right: 12px;
                        }
                    }
                    .form-address, .full-address-info {
                        width: 100%;
                        .province, .city, .area {
                            width: 29.5%;
                            .el-input {
                                width: 100%;
                            }
                        }
                        .address {
                            width: 545px;
                        }
                    }
                }
            }
            .el-dialog__footer {
                text-align: right;
            }
        }
    }
</style>
